using System;
using UnityEngine;
using UnityEngine.UI;

namespace MaterialUI
{
	public class DialogAnimatorSlide : DialogAnimator
	{
		public enum SlideDirection
		{
			Bottom,
			Left,
			Top,
			Right
		}

		[SerializeField]
		private SlideDirection m_SlideInDirection;

		[SerializeField]
		private SlideDirection m_SlideOutDirection;

		[SerializeField]
		private Tween.TweenType m_SlideInTweenType = Tween.TweenType.EaseOutQuint;

		[SerializeField]
		private Tween.TweenType m_SlideOutTweenType = Tween.TweenType.EaseInCubed;

		public SlideDirection slideInDirection
		{
			get
			{
				return m_SlideInDirection;
			}
			set
			{
				m_SlideInDirection = value;
			}
		}

		public SlideDirection slideOutDirection
		{
			get
			{
				return m_SlideOutDirection;
			}
			set
			{
				m_SlideOutDirection = value;
			}
		}

		public Tween.TweenType slideInTweenType
		{
			get
			{
				return m_SlideInTweenType;
			}
			set
			{
				if (value == Tween.TweenType.Custom)
				{
					UnityEngine.Debug.LogWarning("Cannot set tween type to 'Custom'");
				}
				else
				{
					m_SlideInTweenType = value;
				}
			}
		}

		public Tween.TweenType slideOutTweenType
		{
			get
			{
				return m_SlideOutTweenType;
			}
			set
			{
				if (value == Tween.TweenType.Custom)
				{
					UnityEngine.Debug.LogWarning("Cannot set tween type to 'Custom'");
				}
				else
				{
					m_SlideOutTweenType = value;
				}
			}
		}

		public DialogAnimatorSlide(float animationDuration = 0.5f)
		{
			m_AnimationDuration = animationDuration;
		}

		public DialogAnimatorSlide(float animationDuration, SlideDirection slideInDirection, SlideDirection slideOutDirection)
		{
			m_AnimationDuration = animationDuration;
			m_SlideInDirection = slideInDirection;
			m_SlideOutDirection = slideOutDirection;
		}

		public DialogAnimatorSlide(float animationDuration, SlideDirection slideInDirection, SlideDirection slideOutDirection, Tween.TweenType slideInTweenType, Tween.TweenType slideOutTweenType)
		{
			m_AnimationDuration = animationDuration;
			m_SlideInDirection = slideInDirection;
			m_SlideOutDirection = slideOutDirection;
			if (slideInTweenType == Tween.TweenType.Custom || slideOutTweenType == Tween.TweenType.Custom)
			{
				UnityEngine.Debug.LogWarning("Cannot set tween type to 'Custom'");
				return;
			}
			m_SlideInTweenType = slideInTweenType;
			m_SlideOutTweenType = slideOutTweenType;
		}

		public override void AnimateShow(Action callback)
		{
			base.AnimateShow(callback);
			LayoutRebuilder.ForceRebuildLayoutImmediate(m_Dialog.rectTransform);
			m_Dialog.rectTransform.anchoredPosition = GetSlidePosition(m_SlideInDirection);
			m_Dialog.rectTransform.localScale = Vector3.one;
			TweenManager.TweenVector2(delegate(Vector2 v2)
			{
				m_Dialog.rectTransform.anchoredPosition = v2;
			}, m_Dialog.rectTransform.anchoredPosition, Vector2.zero, m_AnimationDuration, 0f, callback, scaledTime: false, m_SlideInTweenType);
		}

		public override void AnimateHide(Action callback)
		{
			base.AnimateHide(callback);
			TweenManager.TweenVector2(delegate(Vector2 v2)
			{
				m_Dialog.rectTransform.anchoredPosition = v2;
			}, m_Dialog.rectTransform.anchoredPosition, GetSlidePosition(m_SlideOutDirection), m_AnimationDuration, 0f, callback, scaledTime: false, m_SlideOutTweenType);
		}

		private Vector2 GetSlidePosition(SlideDirection direction)
		{
			float num = (direction != SlideDirection.Left && direction != SlideDirection.Right) ? m_Dialog.rectTransform.GetRootCanvas().pixelRect.height : m_Dialog.rectTransform.GetRootCanvas().pixelRect.width;
			float num2 = (direction != SlideDirection.Left && direction != SlideDirection.Right) ? LayoutUtility.GetPreferredHeight(m_Dialog.rectTransform) : LayoutUtility.GetPreferredWidth(m_Dialog.rectTransform);
			num2 *= 1.1f;
			switch (direction)
			{
			case SlideDirection.Bottom:
				return new Vector2(0f, 0f - (num + num2));
			case SlideDirection.Left:
				return new Vector2(0f - (num + num2), 0f);
			case SlideDirection.Right:
				return new Vector2(num + num2, 0f);
			case SlideDirection.Top:
				return new Vector2(0f, num + num2);
			default:
				return Vector2.zero;
			}
		}
	}
}
